/*
 * @Author: your name
 * @Date: 2021-08-26 11:55:00
 * @LastEditTime: 2021-08-26 18:37:50
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day04\6-this.js
 */
var name = 'zs'; //文件内的全局作用域
//name= 'zs'; //运行环境的全局
function say() {
    //var name = 'zs'; //函数级别作用域

    console.log(this.name, this); // undefined  Object[global]
    //console.log(name, this.name); //zs undefined
    //console.log(name, this.name); //zs zs
}
say();


var age = 100; //文件级别的作用域
function print() {
    var age = 200; //函数级别作用域
    console.log(age, this.age); //200 undefined
}
print();


//就近原则：函数内部--》该文件内部--》运行环境global window
//函数内部指代用arguments   对象内部指代用this 
var classmate = 'hhhh';
var stu = {
    classmate: 'web2103',
    tell: function() {
        console.log(classmate, stu.classmate, this.classmate); //undefined
    }
};
//tell() //!error
stu.tell();
console.log(stu.classmate);




//
function sayName() {
    console.log('函数内:', this.name);
}
var p1 = {
    name: 'terry',
    sayName //等价于sayName:sayName
};
var p2 = {
    name: 'robbin',
    sn: sayName
};
var p3 = {
    sayName
};
p1.sayName();
p2.sn();
p3.sayName();